package tas.co.in.controller.transactions;

import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import tas.co.in.dao.transactions.TransactionApprovalConect;
import tas.co.in.domain.transactions.Transactions;

public class TransactionApproval extends MultiActionController {

	private TransactionApprovalConect transactionApprovalConect;

	/**
	 * @param transactionApprovalConect
	 *            the transactionApprovalConect to set
	 */
	public void setTransactionApprovalConect(
			TransactionApprovalConect transactionApprovalConect) {
		this.transactionApprovalConect = transactionApprovalConect;
	}

	public ModelAndView getTransRequests(HttpServletRequest request,
			HttpServletResponse response) {
		
		Transactions transactions = new Transactions();
		
		transactions.setTransactionStatus(request.getParameter("status"));		

		List<Transactions> resultObject = transactionApprovalConect
				.getTransactionRequests(transactions);

		return new ModelAndView("customerJSP/BufferTransactionRequests",
				"resultObject", resultObject);

	}

	public ModelAndView approveRequests(HttpServletRequest request,
			HttpServletResponse response) {

		HttpSession session = request.getSession(true);

		Transactions transactions = new Transactions();

		transactions.setUserId(session.getAttribute("userId").toString());

		StringTokenizer tokenizer = new StringTokenizer(request
				.getParameter("selectedTransactions"), ",");

		boolean resultObject = transactionApprovalConect
				.approveTransactions(tokenizer,transactions);

		return new ModelAndView("sharedJSP/BooleanResults", "resultObject",
				resultObject);

	}
}
